jQuery(function() {
    if (jQuery('.get-shipping-rates').length > 0) {
        jQuery('.get-shipping-rates').bind('click', function() {
            var pid = jQuery('#shipping_address_id').val();
            if (pid != '') {
                jQuery(this).unbind('click');
                jQuery(this).after('<div class="ajax-progress ajax-progress-throbber"><div class="throbber">&nbsp;</div><div class="message">Please wait...</div></div>');
                jQuery.post(Drupal.settings.basePath + 'cart/shipping-rates', {pid: pid}, function(data) {
                    if (data != '') {
                        jQuery('#shipping_rates_selection').html(data);
                        jQuery('.ajax-progress-throbber').remove();
                    } else {
                        alert('Could not get data.Please try again!');
                    }
                    jQuery(this).bind('click');
                });
            } else {
                alert('Choose address to shipping.');
            }
            return false;
        });
    }
});